//
//  XJYMTTableViewCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/11.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJYMTTableViewCell.h"
@interface XJYMTTableViewCell()
/**1.头像*/
@property(nonatomic, strong) UIImageView *iconIV;
/**2.小区昵称*/
@property(nonatomic, strong) UILabel *xiaoquNameLb;
/**3.多少分钟之前*/
@property(nonatomic, strong) UILabel *timeLb;
/**4.活动名*/
@property(nonatomic, strong) UILabel *activityNameLb;
/**4.活动内容*/
@property(nonatomic, strong) UILabel *actContentLb;
/**5.浏览次数*/
@property(nonatomic, strong) UILabel *countLb;


@end
@implementation XJYMTTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
    }
    return self;
}

#pragma mark - lazy
- (UIImageView *)iconIV {
    if (!_iconIV) {
        _iconIV = [UIImageView new];
        _iconIV.layer.masksToBounds = YES;
        _iconIV.layer.cornerRadius = 20; //iconIV 高度固定 40
//        _iconIV.backgroundColor = [UIColor lightGrayColor];
    }
    return _iconIV;
}
- (UILabel *)xiaoquNameLb {
    if (!_xiaoquNameLb) {
        _xiaoquNameLb  = [UILabel new];
//        _xiaoquNameLb.backgroundColor = [UIColor redColor];
    }
    return _xiaoquNameLb;
}

- (UILabel *)timeLb {
    if (!_timeLb) {
        _timeLb = [UILabel new];
        _timeLb.font = XJFONTSET_R(14);
//        _timeLb.backgroundColor = [UIColor lightGrayColor];
    }
    return _timeLb;
}
- (UILabel *)activityNameLb {
    if (!_activityNameLb) {
        _activityNameLb = [UILabel new];
//        _activityNameLb.backgroundColor = [UIColor lightGrayColor];
    }
    return _activityNameLb;
}
- (UILabel *)actContentLb {
    if (!_actContentLb) {
        _actContentLb = [UILabel new];
        _actContentLb.font = XJFONTSET_R(14);
//        _actContentLb.backgroundColor = [UIColor yellowColor];
    }
    return  _actContentLb;
}
- (UILabel *)countLb {
    if (!_countLb) {
        _countLb = [UILabel new];
        _countLb.textColor = [UIColor lightGrayColor];
        _countLb.font = XJFONTSET_R(13);
        _countLb.textAlignment = NSTextAlignmentRight;
//       _countLb.backgroundColor = [UIColor blueColor];
    }
    return  _countLb;
}

#pragma mark - 添加控件
- (void)setupUI {
    // icon
    self.iconIV.image = [UIImage imageNamed:@"tab_my_off"];
    [self.contentView addSubview:self.iconIV];
    XJLog(@"=====%@",NSStringFromCGRect(self.iconIV.frame));
    
    // 小区名
    self.xiaoquNameLb.text = @"小区昵称";
    [self.contentView addSubview:self.xiaoquNameLb];
    
    // 多少分钟前
    self.timeLb.text = @"9分钟前";

    [self.contentView addSubview:self.timeLb];
    
    // 活动名称
    self.activityNameLb.text = @"羽毛球活动";
    [self.contentView addSubview:self.activityNameLb];
    
    // 活动内容
    self.actContentLb.text = @"今天有活动,在xx小区举办活动";
    [self.contentView addSubview:self.actContentLb];
    
    // 浏览次数
    self.countLb.text = @"10浏览";
    [self.contentView addSubview:self.countLb];
}

#pragma mark - 布局
- (void)layoutSubviews {
    [super layoutSubviews];

    CGFloat margin = 15;
    
    self.iconIV.sd_layout.topSpaceToView(self.contentView, margin).leftSpaceToView(self.contentView, margin).heightIs(40).widthIs(40);
    self.xiaoquNameLb.sd_layout.topSpaceToView(self.contentView, margin).leftSpaceToView(self.iconIV, margin).rightSpaceToView(self.contentView, 10).heightIs(20);
    
    self.timeLb.sd_layout.topSpaceToView(self.xiaoquNameLb, margin/2).leftSpaceToView(self.iconIV, margin).heightIs(15).widthIs(150);
    
    self.activityNameLb.sd_layout.leftSpaceToView(self.contentView, margin).topSpaceToView(self.iconIV, margin*1.5).heightIs(20).widthIs(200);
    
    self.actContentLb.sd_layout.leftEqualToView(self.activityNameLb).topSpaceToView(self.activityNameLb, margin).rightSpaceToView(self.contentView, margin).heightIs(50);
    
    self.countLb.sd_layout.rightSpaceToView(self.contentView, margin * 0.8).bottomSpaceToView(self.contentView, margin * 0.8).heightIs(15).widthIs(150);
}

#pragma mark - 赋值
- (void)configureYMTCellWithAvator:(NSString *)avator time:(NSString *)time name:(NSString *)name title:(NSString *)title content:(NSString *)content clickCount:(NSString *)count {
    
    UIImage *placeImg = [UIImage imageNamed:@"tab_my_off"];
    [self.iconIV sd_setImageWithURL:[NSURL URLWithString:avator] placeholderImage:placeImg];
    self.xiaoquNameLb.text = name;
    self.timeLb.text = time;
    self.activityNameLb.text = title;
    self.actContentLb.text = content;
    
    self.countLb.text = [NSString stringWithFormat:@"%@浏览",count];
    
}


@end
